package initialize

import (
	"encoding/json"
	"server/form"

	"server/model"

	"github.com/gorilla/websocket"
)

var MapChannel = make(chan interface{}, 0)
var DapingNum = 0 // 连接的大屏数量
var WsList []*websocket.Conn
var Limit []form.Position

func PushAllDaping() {
	defer func() {
		recover()
	}()
	// 这个协程 会随着项目启动, 且一直阻塞在这
	for {
		<-MapChannel
		go func() { //推送所有
			for _, conn := range WsList {
				marshal, err := json.Marshal(model.GetDataList())
				if err != nil {
					continue
				}
				//写入ws数据
				err = conn.WriteMessage(1, marshal)
				if err != nil {
					continue
				}
			}
			defer func() {
				recover()
			}()
		}()
	}
}
